package com.dferreira.languagesteach.utils;

import android.content.Context;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ViewFlipper;

import com.dferreira.languagesteach.R;

public class SlideAnimator {
    private final ViewFlipper flipper;
    private final Animation inFromRight;
    private final Animation outToLeft;
    private final Animation inFromLeft;
    private final Animation outToRight;
    private final Animation outToUp;

    /**
     * @param context global information about an application environment.
     * @param flipper Animate between the transition of his children
     */
    public SlideAnimator(Context context, ViewFlipper flipper) {
        this.flipper = flipper;
        inFromRight = AnimationUtils.loadAnimation(context,
                R.anim.in_from_right);
        outToLeft = AnimationUtils.loadAnimation(context, R.anim.out_to_left);
        inFromLeft = AnimationUtils.loadAnimation(context, R.anim.in_from_left);
        outToRight = AnimationUtils.loadAnimation(context, R.anim.out_to_right);
        outToUp = AnimationUtils.loadAnimation(context, R.anim.out_to_up);

    }

    /**
     * Set the animations from the slide going to the next one
     */
    public void setAnimationToNextSlide() {
        this.flipper.setInAnimation(this.inFromRight);
        this.flipper.setOutAnimation(this.outToLeft);
    }

    /**
     * Set the animation when the user is going to the previous slide
     */
    public void setAnimationToPreviousSlide() {
        this.flipper.setInAnimation(this.inFromLeft);
        this.flipper.setOutAnimation(this.outToRight);
    }

    /**
     * @return Animation that show the view going up in the screen
     */
    public Animation getOutToUp() {
        return this.outToUp;
    }
}
